<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div style="padding-bottom:200px" class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">满送设置</label>
        <div class="layui-input-block">
            <button type="button" onclick="additem()" class="layui-btn">添加</button>
        </div>
    </div>
    <div id="bb">
        <div class="layui-form-item ">
            <div class="layui-inline">
                <label class="layui-form-label">充值金币数</label>
                <div class="layui-input-inline ">
                    <input type="number" name="amount[]" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">赠送金币数</label>
                <div class="layui-input-inline">
                    <input type="number" name="give_num[]" value="0" class="layui-input">
                </div>
            </div>

        </div>

    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>


    <!--</form>-->
</div>
{include file="public/footer" /}

<script>

    layui.use(['form', 'wangEditor', 'laydate', 'upload'], function () {
        let form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        //监听提交
        form.on('submit(saveBtn)', function (data) {

            let postdata = data.field

            //发异步，把数据提交给php
            $.ajax({
                url: '/admin/Active/full_delivery?action=add',
                type: 'post',
                dataType: 'json',
                data: postdata,
                success: function (res) {
                    if (res.status == true) {
                        layer.msg('保存成功', {icon: 1, time: 1000},
                            function () {
                                parent.location.reload();
                            })

                    } else {
                        layer.open({
                            title: '错误信息',
                            content: '<span style="color:red">' + res.code + ':</span>' + res.msg
                        })
                        return false
                    }
                },
                error: function (re) {

                    layer.open({
                        title: '错误信息',
                        content: '<span style="color:red">' + re.responseJSON.errorCode + ':</span>' + re.responseJSON.msg
                    })
                }
            });
        });
    });

    /*点击添加阶段*/
    function additem() {
        let new_html = '<div class="layui-form-item" >\n' +
            '            <div class="layui-inline" >\n' +
            '                <label class="layui-form-label">充值金币数</label>\n' +
            '                <div class="layui-input-inline ">\n' +
            '                    <input type="number" name="amount[]"     class="layui-input cycle_min"  >\n' +
            '                </div>\n' +
            '            </div>\n' +
            '            <div class="layui-inline">\n' +
            '                <label class="layui-form-label">赠送金币数</label>\n' +
            '                <div class="layui-input-inline">\n' +
            '                    <input type="number"    name="give_num[]"  min="0"  value="0"   class="layui-input cycle_max">\n' +
            '                </div>\n' +
            '            </div>\n' +
            '            <div class="layui-inline" style="width: 50px">\n' +
            '                <div class="layui-input-inline">\n' +
            '                    <button type="button" onclick="delcycle(this)" class="layui-btn">删除</button>\n' +
            '                </div>\n' +
            '            </div>\n' +
            '        </div>'

        $('#bb').append(new_html);

    }

    function delcycle(obj) {
        $(obj).parents('.layui-form-item').remove();
    }
</script>

</body>
</html>